<!--
 * @Author: daidai
 * @Date: 2022-02-20 16:16:42
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 09:18:22
 * @FilePath: \web-pc\src\pages\big-screen\view\indexs\left-center.vue
-->
<template>
  <Echart id="leftCenter" v-if="pageflag" :options="options" class="left_center_inner" ref="charts" height="230px" />
  <Reacquire v-else @onclick="getData" style="line-height: 200px">
    重新获取
  </Reacquire>
</template>

<script>
import { currentPOST } from 'api/modules';
import { colorsA, colorsB, legend, xAxis, yAxis } from '@/config/EChartVar';
import { graphic } from 'echarts';

export default {
  data() {
    return {
      options: {},
      tag: 1,
      countUserNumData: {
        axisData: ['2020', '2021', '2022', '2023', '2024'],
        data0: [700, 770, 830, 750, 680],
        data1: [440, 580, 620, 530, 480],
        data2: [380, 350, 460, 440, 380],
        data3: [180, 240, 250, 260, 270]
      },
      pageflag: true,
      timer: null,
    };
  },
  created() {
    this.getData();
  },
  mounted() { },
  beforeDestroy() {
    this.clearData();
  },
  methods: {
    clearData() {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
    },
    getData() {
      this.pageflag = true;

      this.$nextTick(() => {
        this.init(this.countUserNumData);
      });
      // this.switper();
    },
    //轮询
    switper() {
      if (this.timer) {
        return;
      }
      let looper = (a) => {
        this.getData();
      };
      this.timer = setInterval(
        looper,
        2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
      );
      let myChart = this.$refs.charts.chart;
      myChart.on('mouseover', (params) => {
        this.clearData();
      });
      myChart.on('mouseout', (params) => {
        this.timer = setInterval(
          looper,
          2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
        );
      });
    },
    init(currentData) {
      // let axisData = ["2021年", "2022年", "2023年", "2024年"];
      let axisData = currentData.axisData;
      let seriesData = [
        [...currentData.data0],
        [...currentData.data1],
        [...currentData.data2],
        [...currentData.data3]
      ];

      const options = {
        grid: {
          top: '10%',
          left: '4%',
          right: '8%',
          bottom: '6%',
          containLabel: true,
        },
        legend: {
          show: false,
          // x: "center",
          // y: "25",
          top: '1%',
          left: '4%',
          icon: 'circle',
          itemWidth: 12,
          itemHeight: 12,
          // itemGap: 60,
          textStyle: legend.textStyle,
          data: ['票数(票)', '体积(方)', '运费(万)', '重量(吨)'],
        },
        xAxis: {
          type: 'category',
          data: axisData,
          boundaryGap: false,
          // boundaryGap: true,
          splitLine: {
            show: false,
          },
          axisTick: {
            show: false, // 不显示下切线
          },
          axisLabel: xAxis.axisLabel,
          axisLine: {
            lineStyle: {
              background: 'rgba(176, 215, 255, 0.4)',
            },
          },
        },
        yAxis: [
          {
            type: 'value',
            // max: 800,
            // min: 0,//
            axisLabel: yAxis.axisLabel,
            axisLine: {
              show: false,
              lineStyle: {
                color: 'rgba(0,0,0,0.5)',
              },
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: ['rgba(176, 215, 255, 0.2)'],
                width: 1,
                type: 'dashed',
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [],
      };
      const series = [
        {
          name: '票数(票)',
          type: 'line',
          // 动画配置
          animation: true,
          animationDuration: 2000,
          animationEasing: 'quarticInOut',
          animationDelay: function (idx) {
            return idx * 150;
          },
          symbol: 'circle',
          data: seriesData[0],
          itemStyle: {
            normal: {
              color: '#DD16DA',
            },
          },
          lineStyle: {
            normal: {
              width: 2,
            },
          },
          label: {
            show: false,
            position: 'top',
            formatter: (par) => {
              return par.value;
            },
            textStyle: { fontSize: 11, color: '#DD16DA' },
          },
          markPoint: {
            symbol: 'circle',
            symbolSize: [1, 1], // 容器大小
            symbolOffset: ['0%', '0%'],
            data: [
              {
                name: '最大值',
                type: 'max',
                valueIndex: 1,
              },
            ],
            label: {
              show: true,
              position: 'top',
              fontSize: 12,
              color: '#DD16DA',
              formatter: (par) => {
                return '票数(票)';
              },
            },
          },
        },
        {
          name: '体积(方)',
          type: 'line',
          // 动画配置
          animation: true,
          animationDuration: 2000,
          animationEasing: 'quarticInOut',
          animationDelay: function (idx) {
            return idx * 150;
          },
          // smooth: true,
          // showSymbol: false,
          symbol: 'circle',
          // showSymbol: true,
          // symbol: 'circle',
          data: seriesData[1],
          // areaStyle: {
          //   color: colorsB[1],
          // },
          itemStyle: {
            normal: {
              color: '#287CE8',
            },
          },
          lineStyle: {
            normal: {
              width: 2,
            },
          },

          label: {
            show: false,
            position: 'top',
            formatter: (par) => {
              return par.value;
            },
            textStyle: { fontSize: 11, color: '#287CE8' },
          },
          markPoint: {
            symbol: 'circle',
            symbolSize: [1, 1], // 容器大小
            symbolOffset: ['0%', '0%'],
            data: [
              {
                name: '最大值',
                type: 'max',
                valueIndex: 1,
              },
            ],
            label: {
              show: true,
              position: 'top',
              fontSize: 12,
              color: '#287CE8',
              formatter: (par) => {
                return '体积(方)';
              },
            },
          },
        },
        {
          name: '运费(万)',
          type: 'line',
          // 动画配置
          animation: true,
          animationDuration: 2000,
          animationEasing: 'quarticInOut',
          animationDelay: function (idx) {
            return idx * 150;
          },
          // smooth: true,
          // showSymbol: false,
          symbol: 'circle',
          symbolSize: 6,
          data: seriesData[2],
          itemStyle: {
            normal: {
              // color: "#287CE8",
              color: 'rgba(0,219,254,1)',
            },
          },
          // areaStyle: {
          //   color: colorsA[0],
          // },
          lineStyle: {
            normal: {
              width: 2,
            },
          },
          label: {
            show: false,
            position: 'top',
            formatter: (par) => {
              return par.value;
            },
            textStyle: { fontSize: 11, color: 'rgba(0,219,254,1)' },
          },
          markPoint: {
            symbol: 'circle',
            symbolSize: [1, 1], // 容器大小
            symbolOffset: ['0%', '0%'],
            data: [
              {
                name: '最大值',
                type: 'max',
                valueIndex: 1,
              },
            ],
            label: {
              show: true,
              position: 'top',
              fontSize: 12,
              color: 'rgba(0,219,254,1)',
              formatter: (par) => {
                return '运费(万)';
              },
            },
          },
        },
        {
          name: '重量(吨)',
          type: 'line',
          // 动画配置
          animation: true,
          animationDuration: 2000,
          animationEasing: 'quarticInOut',
          animationDelay: function (idx) {
            return idx * 150;
          },
          symbol: 'circle',
          data: seriesData[3],
          itemStyle: {
            normal: {
              color: '#FF0000',
            },
          },
          lineStyle: {
            normal: {
              width: 2,
            },
          },
          label: {
            show: false,
            position: 'top',
            formatter: (par) => {
              return par.value;
            },
            textStyle: { fontSize: 11, color: '#FF0000' },
          },
          markPoint: {
            symbol: 'circle',
            symbolSize: [1, 1], // 容器大小
            symbolOffset: ['0%', '0%'],
            data: [
              {
                name: '最大值',
                type: 'max',
                valueIndex: 1,
              },
            ],
            label: {
              show: true,
              position: 'top',
              fontSize: 12,
              color: '#FF0000',
              formatter: (par) => {
                return '重量(吨)';
              },
            },
          },
        }
      ];
      options.series = series;
      this.options = options;
    },
  },
};
</script>
<style lang="scss" scoped></style>
